package tree.easy;

import tree.Node;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * 559. N 叉树的最大深度
 */
public class NTreeMaxDepth {

    /**
     *
     * @param root
     * @return
     */
    public int maxDepth(Node root) {
        if (root == null) {
            return 0;
        } else if (root.children.isEmpty()) {
            return 1;
        } else {
            List<Integer> list = new ArrayList<>();
            for (Node child : root.children) {
                int nodeDeep = maxDepth(child) + 1;
                list.add(nodeDeep);
            }
            return Collections.max(list);
        }
    }

    public int maxDepth2(Node root) {
        if (root == null) {
            return 0;
        }
//        else if (root.children.isEmpty()) {
//            return 1;
//        } else {
            int max = 0;
            for (Node child : root.children) {
                max = Math.max(maxDepth2(root), max);
            }
            return max;

//        }
    }
}
